package com.breaking.second.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;

import androidx.annotation.Nullable;

import com.breaking.second.activity.login.LoginActivity;
import com.breaking.second.databinding.ActivityMainBinding;
import com.breaking.second.entity.UserLoginEntity;
import com.breaking.second.utils.SecurePreferencesUtil;

//启动页
public class MainActivity extends BaseActivity<ActivityMainBinding> {
    private final CountDownTimer countDownTimer = new CountDownTimer(2500, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {
            Context context = getApplicationContext();
            SecurePreferencesUtil securePreferencesUtil = new SecurePreferencesUtil(UserLoginEntity.class.getName());
            if (securePreferencesUtil.getDecryptedString(context, "data", null) == null) {
                startActivity(new Intent(context, LoginActivity.class));
            } else {
                startActivity(new Intent(context, PagerActivity.class));
            }
            finish();
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        countDownTimer.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        countDownTimer.cancel();
    }
}
